import api from './api';

// 获取用户列表
export const getUsers = async (filters = {}) => {
  try {
    const response = await api.post('/users', filters);
    return response;
  } catch (error) {
    console.error('API 错误:', error);
    throw error;
  }
};

// 添加用户
export const addUser = async (userData) => {
  try {
    const response = await api.post('/register', userData);
    return response;
  } catch (error) {
    throw error;
  }
};

// 更新用户
export const updateUser = async (id, userData) => {
  try {
    const response = await api.post(`/users/${id}`, userData);
    return response;
  } catch (error) {
    throw error;
  }
};

// 删除用户
export const deleteUser = async (userId) => {
  try {
    const response = await api.delete(`/users/${userId}`);
    return response;
  } catch (error) {
    throw error;
  }
};

export const getExportUsers = async (ids) => {
  try {
    const response = await api.get('/usersExport', {
      params: { ids: ids.join(',') },
      responseType: 'blob', // 设置响应类型为 blob
    });
    return response;
  } 
  catch (error) {
    throw error;
  }
};